<?php
session_start();
include_once 'functions/function.php';
include_once 'functions/index.class.php';
include_once 'functions/newReply.class.php';
include 'config/dataSource.php';
include 'addFile.class.php';
$Db = Db();


if(!isset($_SESSION['id'])){
    
    session_start();
    session_unset();
    session_destroy();

    header('Location: index.php');
}




if(isset($_POST['topicTitle']) AND isset($_POST['reply']) AND isset($_FILES['uploadAdminReply']) AND isset($_POST['replyID'])){
    
    $file;
    $fileStatus=false;
    if(isset($_FILES['uploadAdminReply'])){
        echo '<script type="text/javascript">alert("Data has been submitted");</script>';
        $file = new File($_FILES['uploadAdminReply']);
        if($_FILES['uploadAdminReply']['error']==0){
            $fileStatus=true;
        }
    }
    
    $newReply = new newReply($_POST['topicTitle'], $_POST['reply'], $_POST['replyID']);
   
   $error = $newReply->check();
    
    if($error == "ok"){
        
        if($newReply->add()){
            
            if($fileStatus){
                
                $fileUser = $_SESSION['id'];
                $forumID;
                $topicID;
                $replyID;
                $forumIDQuery =  mysql_query("SELECT tid,forumID FROM topic WHERE topicTitle='{$_POST['topicTitle']}'");
                
                if(mysql_num_rows($forumIDQuery)>0){
                    $row = mysql_fetch_assoc($forumIDQuery);
                    $forumID=$row['forumID'];
                   
                    $topicID=$row['tid'];
                }
                $replyIDQuery=  mysql_query("SELECT rid FROM reply WHERE topicID='{$topicID}'");
                if(mysql_num_rows($replyIDQuery)>0){
                    while($row = mysql_fetch_assoc($replyIDQuery)){
                        $replyID=$row['rid'];
                    }
                }
                 
               
                $file->saveWithReply($fileUser, $forumID, $replyID);
            }
           
            header('Location: adminHome.php?topicTitle='.$_POST['topicTitle']);
        }
        else{
            
            $error = "Sorry, There was a problem adding your reply";
            $display = $error;
            header('Location: adminHome.php?topicTitle='.$_POST['topicTitle']);
           
        }
        
    }
    else{
        
        $display = $error;
        header('Location: adminHome.php?topicTitle='.$_POST['topicTitle']);
        
    }
    
}


?>




<!DOCTYPE html>
<html>
    <head>
		<link rel="stylesheet" href="css/adminHome.css">
	</head >
	
	
	<body style="background: url(images/background.jpg);">
	
	
		<div id="wrapper">
		
			<div id="head">
		
					<table id="myTable" border=0>
						<tr>
							<td class="leftCell" ><span>Hello!!<span class="newAccount"><?php echo $_SESSION['username']; ?></a></span></td>
							<td class="middleCell" ><a class="newAccount" href="adminHome.php">Home</a></td>
							<td class="rightCell" ><span><a class="newAccount" href="logOut.php">Sign out</a></span></td>
						</tr>
					</table>
		
            </div>
	
		<div id="container">
		
		
			<div id="optionSection">
			
                           
                            <table border="0" id="adminHeader">
                                
                                <tr class="newForum">
                                    <td class="left"><a class="noDecoration4" href="newForumAdmin.php">Create New Forum</a></td>
                                    <td class="right"><a class="noDecoration4" href="manageUser.php">Manage Users</a></td>
                                </tr>
                                
                            </table>
			</div>
                    
                    
                    
                            <div id="myTable2">
			
				<div id="forumSection">
				
                                    
                                    <?php
                                    
                                            if(isset($_GET['isDeletedReply']) AND isset($_GET['topicIdReply']) AND isset($_GET['replyTitleTopic'])){
                                             
                                            $_GET['isDeletedReply'] = htmlspecialchars($_GET['isDeletedReply']);
                                            
                                            $_GET['topicIdReply'] = htmlspecialchars($_GET['topicIdReply']);
                                            
                                            $_GET['replyTitleTopic'] = htmlspecialchars($_GET['replyTitleTopic']);
                                             
                                    
                                            $rid = $_GET['isDeletedReply'];//Reply id to be deleted
                                            
                                            $tid = $_GET['topicIdReply'];//Topic Id related to the reply to be deleted
                                         
                                            $topicTitle = $_GET['replyTitleTopic'];//The name of topic concerned
                                            
                                            $lastUpdatedBy = $_SESSION['id'];//Used to keep track of the user/admin who is doing the deletion
                                            
                                      
                                            //updating the number of replies in the topic concerned to nomber - 1
                                            
                                            $queryUpdate = $Db->prepare("update topic SET numberOfReplies = numberOfReplies - 1, dateCreated = NOW(), lastUpdatedBy = $lastUpdatedBy  where tid = $tid");
                                            
                                            $queryUpdate->execute(array(
                                                        'lastUpdatedBy' => $_SESSION['id'],
                                                        'tid' => $tid,     
                                                            ));
                                        
                                            //
                                           
                                           
                                            //Getting the forumID connected to the topic where the reply i found
                                            
                                            $queryForum = $Db->prepare("select *from topic where tid = $tid");
                                            
                                            $queryForum->execute(array('tid'=>$tid));
                                            
                                            $responseId = $queryForum->fetch();
                                            
                                            $forumID = $responseId['forumID'];
                                           
                                          
                                        
                                           //updating the number of replies in the forum concerned to less than the number actually present in the forum related to the topic to be deleted
                                           //dateCreated is actually the lastDate updated, I interchanged the use of dateCreadted and dateUpdated. So wherever it is dateCreated it is actually dateUpdated and vice versa
                                           //updating the dateUpdated and who did the update also
                                           
                                           $queryUpdate = $Db->prepare("update forum SET numberOfReplies = numberOfReplies - 1, dateCreated = NOW(), lastUpdatedBy = $lastUpdatedBy  where fid = $forumID");
                                          
  
                                                $queryUpdate->execute(array(
                                                        'lastUpdatedBy' => $_SESSION['id'],
                                                        'fid' => $forumID,     
                                                            ));
                                        
                                           
                                            
                                                
                                            //deleting the reply by setting isDeleted to t
                                            $query = $Db->prepare("update reply SET isDeleted = \"t\" where topicID = $tid AND rid = $rid");
                                             
                                            $query->execute(array('topicID'=>$tid,'rid'=>$rid));//execution
                                            
                                            //redirecting the page to the updated page after all these operations have been performed
                                           header("location: adminHome.php?topicTitle=$topicTitle");
                                        
                                             
                                         }
                                        else if(isset($_GET['isDeletedTopic']) AND isset($_GET['forumIdTopic']) AND isset($_GET['forumTitleTopic'])){
                                             
                                            $_GET['isDeletedTopic'] = htmlspecialchars($_GET['isDeletedTopic']);
                                            
                                            $_GET['forumIdTopic'] = htmlspecialchars($_GET['forumIdTopic']);
                                            
                                            $_GET['forumIdTitle'] = htmlspecialchars($_GET['forumTitleTopic']);
                                             
                                    
                                            $topicTitle = $_GET['isDeletedTopic'];//Topic to be deleted
                                            
                                            $forumID = $_GET['forumIdTopic'];//Forum Id related to the topic to be deleted
                                            
                                            $forumTitle = $_GET['forumIdTitle'];//The forum ID concerned
                                            
                                            $lastUpdatedBy = $_SESSION['id'];//Used to keep track of the user/admin who is doing the deletion
                                            
                                      
                                   
                                           //getting the number of replies in the topic concerned
                                           
                                           $queryReplies = $Db->prepare("select *FROM topic where forumID = $forumID AND topicTitle = \"$topicTitle\"");
                                           
                                           $queryReplies->execute(array('forumID' => $forumID,'topicTitle' => $topicTitle));
                                         
                                           $responseReplies = $queryReplies->fetch();
                                           
                                           $replies = $responseReplies['numberOfReplies'];
                                           
                                        
                                           //updating the number of replies and topic in the forum concerned to less than the number actually present in the forum related to the topic to be deleted
                                           //dateCreated is actually the lastDate updated, I interchanged the use of dateCreadted and dateUpdated. So wherever it is dateCreated it is actually dateUpdated and vice versa
                                           //updating the dateUpdated and who did the update also
                                           
                                           $queryUpdate = $Db->prepare("update forum SET numberOfReplies = numberOfReplies - $replies, numberOfTopics = numberOfTopics - 1, dateCreated = NOW(), lastUpdatedBy = $lastUpdatedBy  where fid = $forumID");
                                          
  
                                                $queryUpdate->execute(array(
                                                        'lastUpdatedBy' => $_SESSION['id'],
                                                        'fid' => $forumID,     
                                                            ));
                                        
                                           
                                            
                                                
                                            //deleting the topic by setting isDeleted to t
                                            $query = $Db->prepare("update topic SET isDeleted = \"t\" where topicTitle = \"$topicTitle\" AND forumID = $forumID");
                                             
                                            $query->execute(array('topicTitle'=>$topicTitle,'forumID'=>$forumID));//execution
                                            
                                            //redirecting the page to the updated page after all these operations have been performed
                                           header("location: adminHome.php?forumTitle=$forumTitle");
                                        
                                             
                                         }
                                         else if(isset($_GET['isDeleted'])){
                                             
                                            $_GET['isDeleted'] = htmlspecialchars($_GET['isDeleted']);//Getting the forum to be deleted
                                             
                                    
                                            $forumTitle = $_GET['isDeleted'];
                                            
                                        
                                            
                                            echo "$forumTitle"; //Testing purposes when I was writing the code
                                            
                                            
                                            //Setting the column of the forum to be deleted to true "t"
                                            
                                            $query = $Db->prepare("update forum SET isDeleted = \"t\" where forumTitle = \"$forumTitle\"");
                                            
                                            $query->execute(array('forumTitle'=>$forumTitle));//execution of query
                                            
                                            header('location: adminHome.php');//redirecting to the updated home
                                        
                                             
                                         }
                                            
                                         else if(isset($_GET['forumTitle'])){//If forum has already been selected
                                            
                                           $_GET['forumTitle'] = htmlspecialchars($_GET['forumTitle']);//somehow avoiding user to modify current location from browser
                                           
                                           $value = $_GET['forumTitle'];
                                           
                                            ?>
                                             
                                             <p class="cells2"><span class="noDecoration2"><?php echo $_GET['forumTitle'];?></span></p>
                                             
                                             <br>
                                             
                                             <br>
                                             
                                              <form method="post" action="adminHome.php?forumTitle=<?php echo $_GET['forumTitle']; ?>">
                                             
                                                                        
                                                                        <span class="sorting">
                                                                              <select name="sortTopic" onchange="this.form.submit()">
                                                                                  <option value="" disabled="disabled" selected="selected">Order By</option>
                                                                                    <option value="topicTitle ASC">Topic Name(Ascending)</option>
                                                                                    <option value="topicTitle DESC">Topic Name(Descending)</option>
                                                                                    <option value="numberOfReplies DESC">Most Replies</option>
                                                                                    <option value="numberOfReplies ASC">Least Replies</option>
                                                                                    
                                                                                </select>
                                                                         
                                                                       </span>   
                                             
                                             </form>
                                             
                                             <hr/>
                                             
                                             <p><a href="newTopicAdmin.php?forumId=<?php $query = $Db->prepare("SELECT *FROM forum where forumTitle = :forumTitle"); $query->execute(array('forumTitle'=>$_GET['forumTitle']));//execution
                                             
                                             //$query->execute();
                                             
                                             $forumTitle = $_GET['forumTitle'];
                                             
                                             $response2 = $query->fetch();//fetch
                                             
                                             $forumId1 = $response2['fid'];
                                             
                                             echo $forumId1;?>" class="noDecoration">Add New Topic</a></p>
                                             
                                             <?php
                                             
                                           
                                             $title = $_GET['forumTitle'];//Retrieving all topics belonging to a particular category
                                             
                                             $query = $Db->prepare("SELECT *FROM forum where forumTitle = :forumTitle");//trying to get if of title
                                             
                                             $query->execute(array('forumTitle'=>$_GET['forumTitle']));//execution
                                             
                                             
                                             //$query->execute();
                                             
                                             $response = $query->fetch();//fetch
                                             
                                             $forumId = $response['fid'];//obtain id
                                             
                                             //$query = $Db->prepare("SELECT *FROM topic where forumID = $forumId  AND isDeleted =\"f\"");//select all topics where id match
                                             
                                             
                                             $order = isset($_POST['sortTopic'])?$_POST['sortTopic']:'dateCreated';
                                                if(isset($_POST['sortTopic'])){
                                                    $query = $Db->query("SELECT *FROM topic where forumID = $forumId AND isDeleted =\"f\" ORDER by $order");
                                                   
                                                }
                                                 else {
                                            
                                                    $query = $Db->query("SELECT *FROM topic where forumID = $forumId  AND isDeleted =\"f\"");
                                            }
                                             
                                             
                                             
                                             //$query->execute(array('forumID'=>$forumId));
                                             
                                             $count = 1;
                                             
                                             ?>
                                             
                                             <table border="0" id="topicTable">
                                             
                                              <tr>
                                                  
                                                  <td class="topicNameHeader"> Topic</td>
                                                  <td class="topicAuthorHeader"> Author</td>
                                                  <td class="numberRepliesHeader"> Replies</td>
                                                  <td class="lastUpdateTopicHeader"> last Update</td>
                                              </tr>
                                             <?php
                                             while($response = $query->fetch())  {
                                                     
                                                     if($count==1){
                                               
                                                $count = 0;
                                                }
                                            else{
                                                
                                                $count = 1;
                                                
 
                                            }
                                            
                                            $userId = $response['owner'];
                                            
                                            $lastUp = $response['lastUpdatedBy'];
                                            
                                            $query2 = $Db->query("SELECT *FROM user where id = $userId");
                                            
                                            $query3 = $Db->query("SELECT *FROM user where id = $lastUp");
                                            
                                            $response2 = $query2->fetch();
                                            
                                            $response3 = $query3->fetch();
                                            ?>
                                             
                                             <tr class='cells<?=$count?>'>
                                                 <td class="topicName"><span ><a class="noDecoration" href="adminHome.php?topicTitle=<?php echo $response['topicTitle']; ?>"><?php echo $response['topicTitle'];?></a><br><span class="subs">Created on : <?php echo $response['dateCreated'];?></span><br>
                                                                        <span class="subs"><a class="noDecoration" href="adminHome.php?isDeletedTopic=<?php echo $response['topicTitle'];?>&forumIdTopic=<?php echo $forumId1;?>&forumTitleTopic=<?php echo $forumTitle;?>">Delete</a></span></td>
                                                  <td class="topicAuthor"><span class="noDecoration"><?php echo $response2['firstName']; echo " "; echo $response2['lastName']; echo " "; ?></span></td>
                                                  <td class="numberReplies"><?php echo $response['numberOfReplies'];?></td>
                                                  <td class="lastUpdateTopic"><?php echo $response3['firstName']; echo " "; echo $response3['lastName']; echo " "; ?><br><span class="subs"> On : <?php echo $response['dateUpdated']; ?><span></td>
                                             </tr>
                                             <?php
                                             
                                             }
                                             
                                             ?>
                                             
                                             </table>
                                             <?php
                                             
                                         }
                                         else  if(isset($_GET['topicTitle'])){//if topic has already been selected
                                            
                                                $_GET['topicTitle'] = htmlspecialchars($_GET['topicTitle']);
                                                
                                                $topicTitle = $_GET['topicTitle'];
                                                
                                                //fetching all the contents of the topic selected
                                                 $query = $Db->prepare("SELECT * FROM topic where topicTitle = :topicTitle");
                                               
                                                $query->execute(array('topicTitle'=>$_GET['topicTitle']));
            
                                                 $response = $query->fetch();
                                                    //fetching the person who created the topic
                                                 $subjectOwnerId = $response['owner'];
                                                 
                                                 $query2 = $Db->query("SELECT *FROM user where id = $subjectOwnerId");
                                                 
                                                $response2 = $query2->fetch();
                                                // response contains all the data of the topic selected
                                                //response 2 contains all the details of the eprson who created the topic
                                                 
                                            ?>
                                             
                                             <p class="cells2"><span class="noDecoration2">Topic : <?php echo $_GET['topicTitle']; echo "  ";?></span></p>
                                             
                                             
                                             
                                             <br>
                                             
                                             
                                             <?php
                                             
                                             
                                               
                                                 
                                             //Below, I retrieve all the topic Ids
                                                 $topicId = $response['tid'];
                                             
                                             
                                             
                                             //Retrieve all the replies having the topicId and which aren't deleted
                                             $query = $Db->query("SELECT *FROM reply where topicID = $topicId AND isDeleted = \"f\"");
                                             
                                             ?>
                                             
                                             <table border="0" id="replyTable">
                                                 
                                                 <tr>
                                                     
                                                     <td class="authorReplyHeader"> Author</td>
                                                     <td class="replyPostHeader"> Comment</td>
                                                     
                                                 </tr>
                                                 
                                             <?php
                                             $count = 1;
                                             while($response = $query->fetch()){
                                                if($count==1){
                                               
                                                $count = 0;
                                                }
                                            else{
                                                
                                                $count = 1;
                                                
 
                                            }
                                            
                                            //Retrieving the user id of the person who commented this comment/reply
                                            $userId = $response['owner'];
                                            
                                            //retrieving the name of the person who wrote the comment
                                            $query2 = $Db->query("SELECT *FROM user where id = $userId");
                                            
                                            $response2 = $query2->fetch();
                                            ?>
                                                 
                                             <tr>
                                                     
                                                     <td class="authorReply"><span class="noDecoration"><?php echo $response2['firstName']; echo " "; echo $response2['lastName'];?></span>
                                                     
                                                         <br><span class="subs">Created on : <?php echo $response['dateCreated'];?></span><br>
                                                                <span class="subs"><a class="noDecoration" href="adminHome.php?isDeletedReply=<?php echo $response['rid'];?>&topicIdReply=<?php echo $topicId;?>&replyTitleTopic=<?php echo $topicTitle;?>">Delete</a></span>

                                                     </td>
                                                     <td class="replyPost"><?php 
                                                     $tempReplyID = $response['replyID'];
                                                     
                                                     if(!($response['replyID']=null)){
                                                         
                                                         $quoteExecute = "Select *FROM reply WHERE rid='{$tempReplyID}'";
                                                         $quoteQuery = mysql_query($quoteExecute);
                                                         
                                                         $row = mysql_fetch_assoc($quoteQuery);
                                                         
                                                         if($row['isDeleted']!='t' && mysql_num_rows($quoteQuery)>0){
                                                             echo "<div align=\"left\"><span  style=\"color: #FF4105\">Quote:</span>";
                                                             echo "<table  style=\"border: 1px solid #993CF3 \" ><tr><td>\"{$row['contentOfReply']}\"</td></tr></table></div><br/><br/>";
                                                             
                                                             
                                                         }
                                                         
                                                     } 
                                                     ?>
                                                         <span class="noDecoration"><?php echo $response['contentOfReply'];?></span><br>
                                                     <?php
                                                        $getFileQuery = mysql_query("SELECT * FROM file WHERE replyID={$response['rid']} AND isDeleted='f'");
                                                        if(mysql_num_rows($getFileQuery)==1){
                                                            $row = mysql_fetch_assoc($getFileQuery);
                                                            $encryptFileID = sha1($row['fileID']);
                                                            echo "<br/><p align =\"left\" class=\"noDecoration\">Download: <a href=\"download.php?id={$encryptFileID}\">{$row['name']}</a></p>";
                                                            if(substr($row['mime'],0, 5) =="image"){
                                                                echo "<img src=\"showImage.php?id={$row['fileID']}\" width=\"600\" height=\"400\" align=\"left\"></img>";
                                                            }
                                                            if(substr($row['mime'],0, 5)=="video"){
                                                                
                                                                echo "<div align=\"left\"><video width=\"600\" height=\"400\" controls >";
                                                                echo "<source src=\"showVideo.php?id={$row['fileID']}\" type=\"{$row['mime']}\" ></video></div>";
                                                            }
                                                        }
                                                     ?>
                                                         <form enctype="multipart/form-data" method="POST" action="adminHome.php.php?topicTitle= <?php echo $_GET['topicTitle'] ?>" align="left">
						
							
                                                    <p><textarea name="reply" placeholder="Reply" style=" max-width: 85%; max-height: 30%; resize: auto; overflow: auto" cols="80%" ></textarea></p>
                                                    <input type="hidden" name="topicTitle" value="<?php echo $_GET['topicTitle']; ?>"/>
                                                    <input type="hidden" name="replyID" value="<?php echo $response['rid']; ?>"/>
                                                    <input type="submit" value="Submit reply"/>
                                                    <input type="file" name="uploadReply">
                                                                                                       
						    
                                                    
                                                    
					
                                                    </form> 
                                                         
                                                     </td>
                                                     
                                             </tr>
                                             
                                             
                                             <?php
                                             }
                                             
                                             ?>
                                             
                                             </table>
                                             
                                             <br class="clear">
                                             
                                             <hr/>
                                             
                                             <br class="clear">
                                             
                                            
                                             
                                             
                                             <?php
                                         }
                                         else{
                                         ?>    
                                             <form method="post" action="adminHome.php">
                                             
                                                                        
                                                                        <span class="sorting">
                                                                              <select name="sort" onchange="this.form.submit()">
                                                                                  <option value="" disabled="disabled" selected="selected">Order By</option>
                                                                                    <option value="isPrivate DESC">Forum Type(Private First)</option>
                                                                                    <option value="isPrivate ASC">Forum Type(Public First)</option>
                                                                                    <option value="forumTitle ASC">Forum Name(Ascending)</option>
                                                                                    <option value="forumTitle DESC">Forum Name(Descending)</option>
                                                                                    <option value="members DESC">Highest members</option>
                                                                                    <option value="members ASC">Lowest members</option>
                                                                                    <option value="numberOfTopics+numberOfReplies DESC">Most Active</option>
                                                                                    <option value="numberOfTopics+numberOfReplies ASC">Least Active</option>
                                                                                    <option value="numberOfTopics DESC">Most Topics</option>
                                                                                    <option value="numberOfTopics ASC">Least Topics</option>
                                                                                    <option value="numberOfReplies DESC">Most Replies</option>
                                                                                    <option value="numberOfReplies ASC">Least Replies</option>
                                                                                    
                                                                                </select>
                                                                         
                                                                       </span>   
                                             
                                             </form>
                                         <?php
                                         $order = isset($_POST['sort'])?$_POST['sort']:'dateCreated';
                                         if(isset($_POST['sort'])){
                                               $query = $Db->query("SELECT *FROM forum where isDeleted =\"f\" ORDER by $order");
                                            }
                                        else {
                                            
                                                $query = $Db->query("SELECT *FROM forum where isDeleted =\"f\"");
                                        }
                                        //$query = $Db->query("SELECT *FROM forum where isDeleted =\"f\"");
                                         
                          
                                         
                                         $count = 1;
                                         
                                         ?>
                                        
                                            
                                       <table border="0" id="tableForum">
                                        
                                           <tr>
                                               <td class="forumHeader"> Forum</td>
                                               <td class="authorHeader"> Author</td>
                                               <td class="membersHeader"> Members</td>
                                               <td class="topicsHeader"> Topics</td>
                                               <td class="repliesHeader"> Replies</td>
                                               <td class="lastUpdatedHeader"> Last Update</td>
                                           </tr>
                                         <?php
                                            
                                         while( $response = $query->fetch()){
                                                
                                            if($count==1){
                                               
                                                $count = 0;
                                            }
                                            else{
                                                
                                                $count = 1;
                                            }
                                            
                                            $userId = $response['owner'];
                                          ?>
                                            
                                             
                                                
                                           <!--<tr class='cells'><td class="forum"> -->
                                           <tr class='cells<?=$count?>'>
                                                 
                                           <td class="forum">
                                               <p><a class="noDecoration" href="adminHome.php?forumTitle=<?php echo $response['forumTitle'];?>"><?php echo $response['forumTitle']; if($response['isPrivate']=='t'){ ?> <img src="images/lock2.png" alt="star" height="20" width="20"> <?php } ?></a>
                                                   <br><span class="subs"> Created on : <?php  echo $response['dateUpdated']; ?></span><br>
                                                   <span class="subs"><a class="noDecoration" href="adminHome.php?isDeleted=<?php echo $response['forumTitle'];?>">Delete Forum</a></span><?php 
                                                   
                                                   if($_SESSION['id']==$userId && $response['isPrivate']=='t'){ ?><br>
                                                    <span class="subs"><a class="noDecoration" href="privateForumUsersAdmin.php?forumTitle=<?php echo $response['forumTitle'];?>">Manage Members</a></span><?php }//privateForumUsersAdmin.php is to manage the additon and deletion of users within a forum
                                         
                                                   
                                                   
                                                   
                                                   ?>
                                                   
                                                     </p></td>
                                           
                                           <td class="author"><?php $idUser = $response['owner']; $idUpdate = $response['lastUpdatedBy']; $query2 = $Db->query("SELECT *FROM user where id = $idUser");  
                                           
                                           $responseOwner = $query2->fetch();
                                           
                                           echo $responseOwner['firstName'];
                                           echo " ";
                                           echo $responseOwner['lastName'];
                                           
                                           
                                           ?></td>
                                           
                                           <td class="members"><p><?php if($response['isPrivate']=='f'){ echo "Public";
                                           
                                           $fid = $response['fid'];
                                           
                                           $membersQuery = $Db->query("update forum SET members = 0 where fid = $fid");
                                           }
                                           
                                           else{
                                               
                                               $groupID = $response['fid'];
                                               
                                               
                                               
                                               
                                               $countMembers = $Db->query("select count(*) from private where groupID = $groupID");
                                               
                                               
                                               
                                               
                                               
                                               $responseMembers = $countMembers->fetch();
                                               
                                               
                                               
                                                //$members = $responseMembers["$privateID"];
                                               
                                               echo $responseMembers['count(*)'] + 1;
                                               
                                               $members = $responseMembers['count(*)'] + 1;
                                               $membersQuery = $Db->query("update forum SET members = $members where fid = $groupID");
                                               
                                               
                                               
                                           }
                                           
                                           
                                           
                                           
                                           ?></p></td>
                                           
                                               <td class="topics"><p><?php echo $response['numberOfTopics'];?></p></td>
                                               <td class="replies"><p> <?php echo $response['numberOfReplies'];?></p></td>
                                           <td class="lastUpdated">
                                           <p><?php $query3 = $Db->query("SELECT *FROM user where id = $idUpdate");  
                                           
                                            $responseUpdate = $query3->fetch();
                                           
                                            echo $responseUpdate['firstName'];
                                            echo " ";
                                            echo $responseUpdate['lastName'];
                                            ?>
                                               <br><span class="subs"><?php echo $response['dateCreated'];?></span></p></td>
                                           </tr>
                                                
                                      
                                  
                                            
                                            <?php
                                         }
                                         
                                         ?>
                                         
                                         </table>
                                             
                                                
                                           <?php
                                            }
                                            ?>
                                
                                
                                     <br class="clear" />                                  
                                </div>
                                  
                                    
                                    
                                         
		
                                 
                               
                                
                                
                                <br class="clear" />         
			</div>
	
                    <br class="clear" />
		</div>
		
		<br class="clear" />
		</div>
		<br class="clear" />
                </div>	
	
	</body>
</html>
 



